#pragma once
#include "stdafx.h"
#include "mpqarchive.h"
namespace Moonlite {
namespace Data {
namespace Mpq {
	public ref class TMPQFileStream : System::IO::Stream
	{
	private:
		HANDLE _handle;
		System::String^ _filename;
		TMPQArchive^ _archive;
		__int64 _length;
		__int64 _position;
		std::vector<System::Byte>* _cache;
		System::Object^ _tag;
		bool _disposed;
		void Open();
		void Cleanup(bool managed);
		void CheckBadState();
	public:
		virtual System::Void Close() override;
		array<System::Byte>^ Read(int size);
		array<System::Byte>^ Read(int position, int size);
		virtual int Read(array<System::Byte>^ buffer, int index, int size) override;
		virtual void Write(array<System::Byte>^ buffer, int index, int size) override;
		virtual __int64 Seek(__int64 position, System::IO::SeekOrigin origin) override;
		virtual void SetLength(__int64 length) override;
		virtual void Flush() override;
		virtual property bool CanSeek { bool get() override; }
		virtual property bool CanRead { bool get() override; }
		virtual property bool CanWrite { bool get() override; }
		virtual property __int64 Length { __int64 get() override; }
		virtual property __int64 Position { __int64 get() override; void set(__int64 position) override; }
		property long CompressedLength { long get(); }
		property LCID Locale { LCID get(); void set(LCID locale); }
		property HANDLE Handle { HANDLE get(); }
		property System::String^ FileName { System::String^ get(); }
		property TMPQArchive^ Archive { TMPQArchive^ get(); }
		property System::Object^ Tag { System::Object^ get(); void set(System::Object^ tag); }
		property bool IsDisposed { bool get(); }
		TMPQFileStream(TMPQArchive^ archive, System::String^ filename);
		~TMPQFileStream();
		!TMPQFileStream();
	};
}
}
}